home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / GRAHAM / XA_6S.ZIP / SOURCE / SCRLWIDG.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-08  |  15.0 KB  |  490 lines

  1. /*
  2.  * XaAES - XaAES Ain't the AES
  3.  *
  4.  * A multitasking AES replacement for MiNT
  5.  *
  6.  */
  7.  
  8. #include <OSBIND.H>
  9. #include <VDI.H>
  10. #include <memory.h>
  11. #include "XA_TYPES.H"
  12. #include "XA_DEFS.H"
  13. #include "XA_GLOBL.H"
  14. #include "KERNAL.H"
  15. #include "K_DEFS.H"
  16. #include "BOX3D.H"
  17. #include "KERNAL.H"
  18. #include "DRAG_BOX.H"
  19. #include "GRAF_MOU.H"
  20. #include "MESSAGES.H"
  21. #include "C_WINDOW.H"
  22. #include "RECTLIST.H"
  23. #include "ALL_WIDG.H"
  24. #include "STD_WIDG.H"
  25. #include "SYSTEM.H"
  26. #include "OBJECTS.H"
  27.  
  28. /*
  29.     Scroll bar & Slider handlers
  30. */
  31.  
  32. /*======================================================
  33.     LEFT SCROLL WIDGET BEHAVIOUR
  34. ========================================================*/
  35. short display_lscroll(XA_WINDOW *wind, XA_WIDGET *widg)
  36. {
  37.     short x,y;
  38.  
  39.     rp_2_ap(wind, widg, &x, &y);    /* Convert relative coords and window location to absolute screen location */
  40.  
  41.     if (widg->stat==XAW_PLAIN)
  42.         def_widgets[WIDG_LEFT].ob_state&=~SELECTED;
  43.     else
  44.         def_widgets[WIDG_LEFT].ob_state|=SELECTED;
  45.     
  46.     display_object(def_widgets,WIDG_LEFT,x,y);
  47.  
  48.     return TRUE;
  49. }
  50.  
  51. short click_lscroll(XA_WINDOW *wind, XA_WIDGET *widg)
  52. {
  53.     short mx,my,mb;
  54.     
  55.     send_app_message(wind->owner, WM_ARROWED, 0, wind->handle, WA_LFLINE, 0, 0, 0);
  56.     vq_mouse(V_handle, &mb, &mx, &my);
  57.  
  58.     if (mb)    /* If the button has been held down, set a pending/active widget for the client */
  59.     {
  60.         set_widget_active(wind, widg, &click_lscroll);
  61.         return FALSE;    /* We return false here so the widget display status stays selected whilst it repeats */
  62.     }
  63.     cancel_widget_active(wind);
  64.     return TRUE;
  65. }
  66.  
  67. /*======================================================
  68.     RIGHT SCROLL WIDGET BEHAVIOUR
  69. ========================================================*/
  70. short display_rscroll(XA_WINDOW *wind, XA_WIDGET *widg)
  71. {
  72.     short x,y;
  73.  
  74.     rp_2_ap(wind, widg, &x, &y);    /* Convert relative coords and window location to absolute screen location */
  75.  
  76.     if (widg->stat==XAW_PLAIN)
  77.         def_widgets[WIDG_RIGHT].ob_state&=~SELECTED;
  78.     else
  79.         def_widgets[WIDG_RIGHT].ob_state|=SELECTED;
  80.     
  81.     display_object(def_widgets,WIDG_RIGHT,x,y);
  82.  
  83.     return TRUE;
  84. }
  85.  
  86. short click_rscroll(XA_WINDOW *wind, XA_WIDGET *widg)
  87. {
  88.     short mx,my,mb;
  89.     
  90.     send_app_message(wind->owner, WM_ARROWED, 0, wind->handle, WA_RTLINE, 0, 0, 0);
  91.     vq_mouse(V_handle, &mb, &mx, &my);
  92.  
  93.     if (mb)    /* If the button has been held down, set a pending/active widget for the client */
  94.     {
  95.         set_widget_active(wind, widg, &click_rscroll);
  96.         return FALSE;    /* We return false here so the widget display status stays selected whilst it repeats */
  97.     }
  98.     cancel_widget_active(wind);
  99.     return TRUE;
  100. }
  101.  
  102. /*======================================================
  103.     UP SCROLL WIDGET BEHAVIOUR
  104. ========================================================*/
  105. short display_uscroll(XA_WINDOW *wind, XA_WIDGET *widg)
  106. {
  107.     short x,y;
  108.  
  109.     rp_2_ap(wind, widg, &x, &y);    /* Convert relative coords and window location to absolute screen location */
  110.  
  111.     if (widg->stat==XAW_PLAIN)
  112.         def_widgets[WIDG_UP].ob_state&=~SELECTED;
  113.     else
  114.         def_widgets[WIDG_UP].ob_state|=SELECTED;
  115.     
  116.     display_object(def_widgets,WIDG_UP,x,y);
  117.  
  118.     return TRUE;
  119. }
  120.  
  121. short click_uscroll(XA_WINDOW *wind, XA_WIDGET *widg)
  122. {
  123.     short mx,my,mb;
  124.     
  125.     send_app_message(wind->owner, WM_ARROWED, 0, wind->handle, WA_UPLINE, 0, 0, 0);
  126.     vq_mouse(V_handle, &mb, &mx, &my);
  127.  
  128.     if (mb)    /* If the button has been held down, set a pending/active widget for the client */
  129.     {
  130.         set_widget_active(wind, widg, &click_uscroll);
  131.         return FALSE;    /* We return false here so the widget display status stays selected whilst it repeats */
  132.     }
  133.     cancel_widget_active(wind);
  134.     return TRUE;
  135. }
  136.  
  137. /*======================================================
  138.     DOWN SCROLL WIDGET BEHAVIOUR
  139. ========================================================*/
  140. short display_dscroll(XA_WINDOW *wind, XA_WIDGET *widg)
  141. {
  142.     short x,y;
  143.  
  144.     rp_2_ap(wind, widg, &x, &y);    /* Convert relative coords and window location to absolute screen location */
  145.  
  146.     if (widg->stat==XAW_PLAIN)
  147.         def_widgets[WIDG_DOWN].ob_state&=~SELECTED;
  148.     else
  149.         def_widgets[WIDG_DOWN].ob_state|=SELECTED;
  150.     
  151.     display_object(def_widgets,WIDG_DOWN,x,y);
  152.  
  153.     return TRUE;
  154. }
  155.  
  156. short click_dscroll(XA_WINDOW *wind, XA_WIDGET *widg)
  157. {
  158.     short mx,my,mb;
  159.     
  160.     send_app_message(wind->owner, WM_ARROWED, 0, wind->handle, WA_DNLINE, 0, 0, 0);
  161.     vq_mouse(V_handle, &mb, &mx, &my);
  162.  
  163.     if (mb)    /* If the button has been held down, set a pending/active widget for the client */
  164.     {
  165.         set_widget_active(wind, widg, &click_dscroll);
  166.         return FALSE;    /* We return false here so the widget display status stays selected whilst it repeats */
  167.     }
  168.     cancel_widget_active(wind);
  169.     return TRUE;
  170. }
  171.  
  172. /*======================================================
  173.     VERTICAL SLIDER WIDGET BEHAVIOUR
  174.     The slider widgets are slightly more complex than other widgets
  175.     as they have three seperate 'widgets' inside them.
  176.     (I know GEM doesn't have these, but I think they're cool)
  177. ========================================================*/
  178. short display_vslide(XA_WINDOW *wind, XA_WIDGET *widg)
  179. {
  180.     short x,y,pnt[6],offs,len;
  181.     XA_SLIDER_WIDGET *sl=(XA_SLIDER_WIDGET*)(widg->stuff);
  182.  
  183.     rp_2_ap(wind, widg, &x, &y);    /* Convert relative coords and window location to absolute screen location */
  184.  
  185.     len=(widg->h*sl->length)/1000;
  186.     offs=((widg->h - len)*sl->position)/1000;
  187.  
  188.     if (widg->stat==XAW_PLAIN)
  189.         vsl_color(V_handle,display.dial_colours.t_l_col);
  190.     else
  191.         vsl_color(V_handle,display.dial_colours.b_r_col);
  192.     
  193.     pnt[0]=x+widg->w; pnt[1]=y+offs;
  194.     pnt[2]=x; pnt[3]=y+offs;
  195.     pnt[4]=x; pnt[5]=y+offs+len;
  196.     v_pline(V_handle,3,pnt);
  197.  
  198.     if (widg->stat==XAW_PLAIN)
  199.         vsl_color(V_handle,display.dial_colours.b_r_col);
  200.     else
  201.         vsl_color(V_handle,display.dial_colours.t_l_col);
  202.  
  203.     pnt[2]=x+widg->w; pnt[3]=y+offs+len;
  204.     v_pline(V_handle,3,pnt);
  205.     
  206.     return TRUE;
  207. }
  208.  
  209. short drag_vslide(XA_WINDOW *wind, XA_WIDGET *widg)
  210. {
  211.     short pmx,pmy,mx,my,mb,x,y,wcy,dy;
  212.     short imx,imy,pnt[4],clip[4],offs,noffs,len,orig_offs;
  213.     XA_SLIDER_WIDGET *sl=(XA_SLIDER_WIDGET*)(widg->stuff);
  214.     XA_RECT_LIST *rl=rect_get_system_first(wind);
  215.     XA_CLIENT *client=Pid2Client(wind->owner);
  216.  
  217.     rp_2_ap(wind, widg, &x, &y);    /* Convert relative coords and window location to absolute screen location */
  218.     pnt[0]=x; pnt[1]=y;
  219.     pnt[2]=x+widg->w; pnt[3]=y+widg->h;
  220.     vsf_color(V_handle,display.dial_colours.bg_col);
  221.     vsf_interior(V_handle,FIS_SOLID);
  222.  
  223.     len=(widg->h*sl->length)/1000;
  224.     orig_offs=offs=sl->position;
  225.  
  226.     vq_mouse(V_handle, &mb, &imx, &imy);
  227.     if ((client->widget_active)&&(mb==1))
  228.     {
  229.         imy=client->widget_active->info;
  230.         wcy=1;
  231.     }else{
  232.         wcy=widg->click_y-((widg->h - len)*sl->position)/1000;
  233.     }
  234.     pmx=imx; pmy=imy;
  235.     
  236.     if ((mb)&&((wcy>0)&&(wcy<len)))            /* Drag slider */
  237.     {
  238.         do {
  239.             vq_mouse(V_handle, &mb, &mx, &my);
  240.             if (my!=pmy)            /* Has mouse moved? */
  241.             {
  242.                 dy=(1000*(my-pmy))/(widg->h-len);
  243.                 noffs=offs+dy;
  244.                 if (noffs<0) noffs=0;
  245.                 if (noffs>1000) noffs=1000;
  246.  
  247.                 if (noffs!=offs)    /* Has the slider moved? */
  248.                 {
  249.                     v_hide_c(V_handle);
  250.                     for(rl=rect_get_system_first(wind); rl; rl=rect_get_system_next(wind))                /* Walk the rectangle list */
  251.                     {
  252.                         clip[0]=rl->x; clip[1]=rl->y;
  253.                         clip[2]=rl->x+rl->w; clip[3]=rl->y+rl->h;
  254.                         vs_clip(V_handle,1, clip);
  255.                         v_bar(V_handle,pnt);
  256.                     }
  257.                     offs=noffs;
  258.                     sl->position=offs;
  259.                     for(rl=rect_get_system_first(wind); rl; rl=rect_get_system_next(wind))                /* Walk the rectangle list */
  260.                     {
  261.                         clip[0]=rl->x; clip[1]=rl->y;
  262.                         clip[2]=rl->x+rl->w; clip[3]=rl->y+rl->h;
  263.                         vs_clip(V_handle,1, clip);
  264.                         display_vslide(wind, widg);
  265.                     }
  266.                     v_show_c(V_handle, 1);
  267.                 }
  268.                 pmy=my;
  269.             }
  270. #if REALTIME_SCROLL    
  271.         } while((mb==2)||((mb==1)&&(abs(offs-orig_offs)<RT_SCROLL_STEP)));
  272.         if (mb==1)    /* If the button has been held down, set a pending/active widget for the client */
  273.         {
  274.             set_widget_active(wind, widg, &drag_vslide);
  275.             client->widget_active->info=pmy;
  276.             sl->position=orig_offs;
  277.             send_app_message(wind->owner, WM_VSLID, 0, wind->handle, offs, 0, 0, 0);
  278.             return FALSE;    /* We return false here so the widget display status stays selected whilst it repeats */
  279.         }
  280.         cancel_widget_active(wind);
  281. #else
  282.         } while(mb);
  283. #endif
  284.         sl->position=orig_offs;
  285.         send_app_message(wind->owner, WM_VSLID, 0, wind->handle, offs, 0, 0, 0);
  286.     }else{
  287.         vsf_color(V_handle,display.dial_colours.highlight_col);
  288.         if (wcy<0)                    /* Page left */
  289.         {
  290.             send_app_message(wind->owner, WM_ARROWED, 0, wind->handle, WA_UPPAGE, 0, 0, 0);
  291.             pnt[0]=x; pnt[1]=y;
  292.             pnt[2]=x+widg->w; pnt[3]=y+(widg->h - len)*sl->position/1000;
  293.         }else{                    /* Page right */
  294.             send_app_message(wind->owner, WM_ARROWED, 0, wind->handle, WA_DNPAGE, 0, 0, 0);
  295.             pnt[0]=x; pnt[1]=y+(widg->h - len)*sl->position/1000+len;
  296.             pnt[2]=x+widg->w; pnt[3]=y+widg->h;
  297.         }
  298.         v_hide_c(V_handle);
  299.         for(rl=rect_get_system_first(wind); rl; rl=rect_get_system_next(wind))                /* Walk the rectangle list */
  300.         {
  301.             clip[0]=rl->x; clip[1]=rl->y;
  302.             clip[2]=rl->x+rl->w; clip[3]=rl->y+rl->h;
  303.             vs_clip(V_handle,1, clip);
  304.             v_bar(V_handle,pnt);
  305.             display_vslide(wind, widg);
  306.         }
  307.         v_show_c(V_handle, 1);
  308.         vsf_color(V_handle,display.dial_colours.bg_col);
  309.         if (mb)    /* If the button has been held down, set a pending/active widget for the client */
  310.         {
  311.             set_widget_active(wind, widg, &drag_vslide);
  312.             return FALSE;    /* We return false here so the widget display status stays selected whilst it repeats */
  313.         }
  314.         cancel_widget_active(wind);
  315.     }
  316.     
  317.     v_hide_c(V_handle);
  318.     for(rl=rect_get_system_first(wind); rl; rl=rect_get_system_next(wind))    /* erase the dragged slider */
  319.     {
  320.         clip[0]=rl->x; clip[1]=rl->y;
  321.         clip[2]=rl->x+rl->w; clip[3]=rl->y+rl->h;
  322.         vs_clip(V_handle,1, clip);
  323.         v_bar(V_handle,pnt);
  324.     }                /* We don't need to re-draw the slider as it get's redrawn by the  */
  325.                     /* standard widget handler anyway. */
  326.     v_show_c(V_handle, 1);
  327.  
  328.     return TRUE;
  329. }
  330.  
  331. /*======================================================
  332.     HORIZONTAL SLIDER WIDGET BEHAVIOUR
  333.     The slider widgets are slightly more complex than other widgets
  334.     as they have three seperate 'widgets' inside them.
  335.     (I know GEM doesn't have these, but I think they're cool)
  336. ========================================================*/
  337.  
  338. short display_hslide(XA_WINDOW *wind, XA_WIDGET *widg)
  339. {
  340.     short x,y,pnt[6],offs,len;
  341.     XA_SLIDER_WIDGET *sl=(XA_SLIDER_WIDGET*)(widg->stuff);
  342.  
  343.     rp_2_ap(wind, widg, &x, &y);    /* Convert relative coords and window location to absolute screen location */
  344.  
  345.     len=(widg->w*sl->length)/1000;
  346.     offs=((widg->w - len)*sl->position)/1000;
  347.  
  348.     if (widg->stat==XAW_PLAIN)
  349.         vsl_color(V_handle,display.dial_colours.t_l_col);
  350.     else
  351.         vsl_color(V_handle,display.dial_colours.b_r_col);
  352.     
  353.     pnt[0]=x+offs; pnt[1]=y+widg->h;
  354.     pnt[2]=x+offs; pnt[3]=y;
  355.     pnt[4]=x+offs+len; pnt[5]=y;
  356.     v_pline(V_handle,3,pnt);
  357.  
  358.     if (widg->stat==XAW_PLAIN)
  359.         vsl_color(V_handle,display.dial_colours.b_r_col);
  360.     else
  361.         vsl_color(V_handle,display.dial_colours.t_l_col);
  362.  
  363.     pnt[2]=x+offs+len; pnt[3]=y+widg->h;
  364.     v_pline(V_handle,3,pnt);
  365.     
  366.     return TRUE;
  367. }
  368.  
  369. short drag_hslide(XA_WINDOW *wind, XA_WIDGET *widg)
  370. {
  371.     short pmx,pmy,mx,my,mb,x,y,wcx;
  372.     short imx,imy,pnt[4],clip[4],offs,noffs,len,dx,orig_offs;
  373.     XA_SLIDER_WIDGET *sl=(XA_SLIDER_WIDGET*)(widg->stuff);
  374.     XA_RECT_LIST *rl=rect_get_system_first(wind);
  375.     XA_CLIENT *client=Pid2Client(wind->owner);
  376.  
  377.     rp_2_ap(wind, widg, &x, &y);    /* Convert relative coords and window location to absolute screen location */
  378.     pnt[0]=x; pnt[1]=y;
  379.     pnt[2]=x+widg->w; pnt[3]=y+widg->h;
  380.     vsf_color(V_handle,display.dial_colours.bg_col);
  381.     vsf_interior(V_handle,FIS_SOLID);
  382.  
  383.     len=(widg->w*sl->length)/1000;
  384.     orig_offs=offs=sl->position;
  385.  
  386.     vq_mouse(V_handle, &mb, &imx, &imy);
  387.     if ((mb==1)&&(client->widget_active))
  388.     {
  389.         imx=client->widget_active->info;
  390.         wcx=1;
  391.     }else{
  392.         wcx=widg->click_x-((widg->w - len)*sl->position)/1000;
  393.     }pmx=imx; pmy=imy;
  394.  
  395.     if ((mb)&&((wcx>0)&&(wcx<len)))            /* Drag slider */
  396.     {
  397.         do {
  398.             vq_mouse(V_handle, &mb, &mx, &my);
  399.             if (mx!=pmx)                    /* Has mouse moved? */
  400.             {
  401.                 dx=(1000*(mx-pmx))/(widg->w-len);
  402.                 noffs=offs+dx;
  403.                 if (noffs<0) noffs=0;
  404.                 if (noffs>1000) noffs=1000;
  405.  
  406.                 if (noffs!=offs)            /* Has the slider moved? */
  407.                 {
  408.                     v_hide_c(V_handle);
  409.                     for(rl=rect_get_system_first(wind); rl; rl=rect_get_system_next(wind))                /* Walk the rectangle list */
  410.                     {
  411.                         clip[0]=rl->x; clip[1]=rl->y;
  412.                         clip[2]=rl->x+rl->w; clip[3]=rl->y+rl->h;
  413.                         vs_clip(V_handle,1, clip);
  414.                         v_bar(V_handle,pnt);
  415.                     }
  416.                     offs=noffs;
  417.                     sl->position=offs;
  418.                     for(rl=rect_get_system_first(wind); rl; rl=rect_get_system_next(wind))                /* Walk the rectangle list */
  419.                     {
  420.                         clip[0]=rl->x; clip[1]=rl->y;
  421.                         clip[2]=rl->x+rl->w; clip[3]=rl->y+rl->h;
  422.                         vs_clip(V_handle,1, clip);
  423.                         display_hslide(wind, widg);
  424.                     }
  425.                     v_show_c(V_handle, 1);
  426.                 }
  427.                 pmx=mx;
  428.             }
  429. #if REALTIME_SCROLL    
  430.         } while((mb==2)||((mb==1)&&((abs(offs-orig_offs)<RT_SCROLL_STEP))));
  431.         if (mb)        /* If the button has been held down, set a pending/active widget for the client */
  432.         {
  433.             set_widget_active(wind, widg, &drag_hslide);
  434.             sl->position=orig_offs;
  435.             client->widget_active->info=pmx;
  436.             send_app_message(wind->owner, WM_HSLID, 0, wind->handle, offs, 0, 0, 0);
  437.             return FALSE;    /* We return false here so the widget display status stays selected whilst it repeats */
  438.         }
  439.         cancel_widget_active(wind);
  440. #else
  441.         } while(mb);
  442. #endif
  443.  
  444.         sl->position=orig_offs;
  445.         send_app_message(wind->owner, WM_HSLID, 0, wind->handle, offs, 0, 0, 0);
  446.     }else{
  447.         vsf_color(V_handle,display.dial_colours.highlight_col);
  448.         if (wcx<0)            /* Page left */
  449.         {
  450.             send_app_message(wind->owner, WM_ARROWED, 0, wind->handle, WA_LFPAGE, 0, 0, 0);
  451.             pnt[0]=x; pnt[1]=y;
  452.             pnt[2]=x+(widg->w - len)*sl->position/1000; pnt[3]=y+widg->h;
  453.         }else{                    /* Page right */
  454.             send_app_message(wind->owner, WM_ARROWED, 0, wind->handle, WA_RTPAGE, 0, 0, 0);
  455.             pnt[0]=x+(widg->w - len)*sl->position/1000+len; pnt[1]=y;
  456.             pnt[2]=x+widg->w; pnt[3]=y+widg->h;
  457.         }
  458.         v_hide_c(V_handle);
  459.         for(rl=rect_get_system_first(wind); rl; rl=rect_get_system_next(wind))                /* Walk the rectangle list */
  460.         {
  461.             clip[0]=rl->x; clip[1]=rl->y;
  462.             clip[2]=rl->x+rl->w; clip[3]=rl->y+rl->h;
  463.             vs_clip(V_handle,1, clip);
  464.             v_bar(V_handle,pnt);
  465.             display_hslide(wind, widg);
  466.         }
  467.         v_show_c(V_handle, 1);
  468.         vsf_color(V_handle,display.dial_colours.bg_col);
  469.         if (mb)    /* If the button has been held down, set a pending/active widget for the client */
  470.         {
  471.             set_widget_active(wind, widg, &drag_hslide);
  472.             return FALSE;    /* We return false here so the widget display status stays selected whilst it repeats */
  473.         }
  474.         cancel_widget_active(wind);
  475.     }
  476.     
  477.     v_hide_c(V_handle);
  478.     for(rl=rect_get_system_first(wind); rl; rl=rect_get_system_next(wind))        /* erase the dragged slider */
  479.     {
  480.         clip[0]=rl->x; clip[1]=rl->y;
  481.         clip[2]=rl->x+rl->w; clip[3]=rl->y+rl->h;
  482.         vs_clip(V_handle,1, clip);
  483.         v_bar(V_handle,pnt);
  484.     }                /* We don't need to re-draw the slider as it get's redrawn by the  */
  485.                     /* standard widget handler anyway. */
  486.     v_show_c(V_handle, 1);
  487.  
  488.     return TRUE;
  489. }
  490.